
import { random } from '@/utils/number.js'
import { isArray } from 'lodash'

const weekday = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]

const legend = ['直接访问', '搜索引擎']

// 获取轴
export const axis = (type) => {
  return [...weekday]
}

export const getValue = (num = 7) => {
  const value = []
  for (let i = 0; i < num; i++) {
    value.push(random(0, 100))
  }
  return value
}

export const getSeries = (legend) => {
  let list = []
  legend.forEach((o, i) => {
    list.push({
      type: o,
      value: getValue()
    })
  })
  return list
}

export const getData = (type) => {
  let series = [legend[0]]
  if (['stackArea', 'groupBar', 'stackBar', 'groupColumn', 'stackColumn'].indexOf(type) > -1) {
    series = legend
  }
  return {
    axis: axis(),
    list: getSeries(series)
  }
}

// 转换成图表加载数据
export const transformData = (data) => {
  let list = []
  data.list.forEach(o => {
    if (isArray(o.value)) {
      o.value.forEach((v, i) => {
        list.push({
          x: data.axis[i],
          type: o.type,
          value: v
        })
      })
    } else {
      list.push({
        type: o.type,
        value: o.value
      })
    }
  })
  return list
}


export const defaultData = {
  line: getData('line'),
  stepLine: getData('line'),
  area: getData('area'),
  stackArea: getData('stackArea'),
  bar: getData('bar'),
  groupBar: getData('groupBar'),
  stackBar: getData('stackBar'),
  column: getData('column'),
  groupColumn: getData('groupColumn'),
  stackColumn: getData('stackColumn'),
  wordCloud: (function(){
    const arr = ['白酒', '贵州茅台', '五粮液', '洋河', '山西汾酒', '泸州老窖', '舍得酒业', '古井贡酒', '剑南春', '酒鬼酒', '伊力特', '郎酒']
    let list = []
    for(let i = 0; i < arr.length; i++) {
      list.push({
        type: arr[i],
        value: random(0, 1000)
      })
    }
    return {
      list: list
    }
  })(),
  pie: {
    list: [
      { type: '分类一', value: random(1, 100) },
      { type: '分类二', value: random(1, 100) },
      { type: '分类三', value: random(1, 100) },
      { type: '分类四', value: random(1, 100) },
      { type: '分类五', value: random(1, 100) },
      { type: '其他', value: random(1, 100) }
    ]
  },
  funnel: {
    list: [
      { type: '简历筛选', value: 253 },
      { type: '初试人数', value: 151 },
      { type: '复试人数', value: 113 },
      { type: '录取人数', value: 87 },
      { type: '入职人数', value: 59 }
    ]
  },
  ring: {
    list: [
      { type: '分类一', value: random(1, 100) },
      { type: '分类二', value: random(1, 100) },
      { type: '分类三', value: random(1, 100) },
      { type: '分类四', value: random(1, 100) },
      { type: '分类五', value: random(1, 100) },
      { type: '其他', value: random(1, 100) }
    ]
  },
  dualAxes: {
    list: []
  },
  liquid: {
    value: 0.66
  },
  gauge: {
    value: 0.55
  },
  radar: getData('radar'),
  number: {
    value: 34509
  },
  multipleNumber: {
    list: [{
      type: '今日PV',
      value: random(1, 1000000)
    },{
      type: '今日PV',
      value: random(1, 1000000)
    },{
      type: '今日PV',
      value: random(1, 1000000)
    },{
      type: '今日PV',
      value: random(1, 1000000)
    },{
      type: '今日PV',
      value: random(1, 1000000)
    }]
  },
  trendNumber: getData('trendNumber'),
  excel: {
    list: []
  },
  markdown: {
    value: ''
  },
  richText: {
    value: ''
  },
  carousel: {
    list: []
  }
}
export default (type) => {
  return defaultData[type] || null
}